﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Canyala.Lagoon.Engineering
{
    public partial class Unit
    {
        private static void InitializeUnits()
	    {
            CreateUnit("meter", "m", "distance");
            CreateUnit("mol", "mol", "quantity");
            CreateUnit("gram", "g", "mass");
            CreateUnit("second", "s", "time");
            CreateUnit("candela", "cd", "luminosity");
            CreateUnit("farad", "F", "capacitance");
            CreateUnit("hertz", "Hz", "frequency");
            CreateUnit("joule", "J", "current");
            CreateUnit("newton", "N", "force");
            CreateUnit("pascal", "Pa", "pressure");
            CreateUnit("watt", "W", "power");
            CreateUnit("area", "m2", "surface");
            CreateUnit("volume", "m3", "space");
            CreateUnit("miles", "m/s", "velocity");
            CreateUnit("ohm", "Ω", "restistance");
            CreateUnit("volt", "V", "voltage");
            CreateUnit("ampere", "A", "current");            
            CreateUnit("kelvin", "°K", "temperature");
            CreateUnit("celcius", "°C", "temperature");
            CreateUnit("fahrenheit", "°F", "temperature");

            CreateConversion("celcius", "fahrenheit", "(°F-32)*5/9");
            CreateConversion("celcius", "kelvin", "°K-273.15");

            CreateConversion("fahrenheit", "celcius", "°C*9/5+32");
            CreateConversion("fahrenheit", "kelvin", "((°K-273.15)*1.8)+32");
	    }

        private static void CreateConversion(string from, string to, string expression)
        {            
            Conversion conversion = new Conversion { Unit = to, Expression = expression };
            unitsByName[from].conversions.Add(to, conversion);
        }

        private static Unit CreateUnit(string name, string symbol, string dimenstion)
        {
            var unit = new Unit { Name = name, Symbol = symbol, Dimension = dimenstion };
            
            unitsBySymbol.Add(unit.Symbol, unit);
            unitsByName.Add(unit.Name, unit);
            return unit;
        }
    }
}
